import { Space, Tag } from "antd";
import { SalesNeedInfoProps } from "./data";
import { forwardRef, useState } from "react";
import { ProDescriptions } from "@ant-design/pro-components";
import styles from './descriptionStyles.less';

const Content: React.FC<SalesNeedInfoProps> = (props, uploadRef) => {
  // const [props.checkedKeys, setprops.checkedKeys] = useState<React.Key[]>([]);
  const stackerDriveTypeMap = new Map([
    [1, 'G120 CU250S-2'],
    [2, 'G120 CU240E-2'],
    [3, 'G120C'],
    [4, 'S120 CU320-2'],
    [5, 'S120 CU310-2'],
    [6, 'V90'],
    [0, 'Others'],
  ]);

  const stackerControlModeMap = new Map([
    [1, 'Epos定位'],
    [2, '速度闭环控制'],
    [3, '无编码器矢量控制'],
    [4, 'V/F'],
  ]);

  const motorManufacturerMap = new Map([
    [1, 'SIEMENS'],
    [2, 'SEW'],
    [0, 'Others'],
  ]);

  const stackerMotorWiringMap = new Map([
    [1, '▲'],
    [2, 'Y'],
  ]);

  const stackerMotorBrakeMap = new Map([
    [0, '不带抱闸'],
    [1, '带抱闸'],
  ]);

  const stackerEncoderInterfaceMap = new Map([
    [1, '端子'],
    [2, 'D-Sub'],
  ]);

  const stackerSigPolarityMap = new Map([
    [1, '单极性'],
    [2, '双极性'],
  ]);

  const driveTypeMap = new Map([
    [1, 'V90'],
    [2, 'S210'],
  ]);

  const loadTypeMap = new Map([
    [1, '水平'],
    [2, '旋转'],
    [3, '垂直'],
    [4, '斜坡'],
    [5, '其它'],
  ]);

  const mechanicalStructureMap = new Map([
    [1, '丝杠'],
    [2, '齿轮齿条'],
    [3, '皮带轮'],
    [4, '圆盘'],
    [5, '辊式带'],
    [6, '链条'],
  ]);

  const controlModeMap = new Map([
    [1, 'TO'],
    [2, 'Epos'],
    [3, 'Speed'],
  ]);

  const commTelegramMap = new Map([
    [105, '105'],
    [111, '111'],
    [102, '102'],
    [3, '3'],
    [1, '1'],
  ]);

  const additionalTelegramMap = new Map([
    [999, 'None'],
    [750, '750'],
  ]);

  const timeMap = new Map([
    [1, '<0.05'],
    [2, '0.05-0.09'],
    [3, '0.1-0.2'],
    [4, '0.25-0.4'],
    [5, '0.45-0.9'],
    [6, '1.0-2.0'],
    [7, '2.0-4.0'],
    [8, '>4.0'],
  ]);

  if (props.isStacker) {
    return (
      <div>
        <ProDescriptions
          title={<div style={{ fontSize: '14px' }}>基本信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={4}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                velocityMax: props.row.velocityMax,
                accelerationMax: props.row.accelerationMax,
                gearRationMotor: props.row.gearRationMotor,
                gearRationLoad: props.row.gearRationLoad,
                loadOneTurnDistance: props.row.loadOneTurnDistance,
                
                driveType: stackerDriveTypeMap.get(props.row.driveType),
                controlMode: stackerControlModeMap.get(props.row.controlMode),
              },
            });
          }}
          columns={[
            {
              title: "最大速度 [m/min]",
              key: 'velocityMax',
              dataIndex: 'velocityMax',
            },
            {
              title: "最大加速度 [m/s²]",
              key: 'accelerationMax',
              dataIndex: 'accelerationMax',
            },
            {
              title: "齿轮比电机",
              key: 'gearRationMotor',
              dataIndex: 'gearRationMotor',
            },
            {
              title: "齿轮比负载",
              key: 'gearRationLoad',
              dataIndex: 'gearRationLoad',
            },
            {
              title: "负载一圈的距离 [mm]",
              key: 'loadOneTurnDistance',
              dataIndex: 'loadOneTurnDistance',
            },
            {
              title: "驱动类型",
              key: 'driveType',
              dataIndex: 'driveType',
            },
            {
              title: "控制模式",
              key: 'controlMode',
              dataIndex: 'controlMode',
            },
          ]}
        ></ProDescriptions>
        <ProDescriptions
          title={<div style={{ fontSize: '14px' }}>电机铭牌信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={4}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                motorManufacturer: props.row.motorManufacturer,
                motorOrderNum: props.row.motorOrderNum,
                motorVoltage: props.row.motorVoltage,
                motorWiring: stackerMotorWiringMap.get(props.row.motorWiring),
                motorPower: props.row.motorPower,
                motorTorque: props.row.motorTorque,
                
                motorCurrent: props.row.motorCurrent,
                motorSpeed: props.row.motorSpeed,
                motorPowerFactor: props.row.motorPowerFactor,
                motorFrequency: props.row.motorFrequency,
                motorBrake: stackerMotorBrakeMap.get(props.row.motorBrake),
              },
            });
          }}
          columns={[
            {
              title: "厂家",
              key: 'motorManufacturer',
              dataIndex: 'motorManufacturer',
            },
            {
              title: "订货号",
              key: 'motorOrderNum',
              dataIndex: 'motorOrderNum',
            },
            {
              title: "电压 [V]",
              key: 'motorVoltage',
              dataIndex: 'motorVoltage',
            },
            {
              title: "接线",
              key: 'motorWiring',
              dataIndex: 'motorWiring',
            },
            {
              title: "功率 [kw]",
              key: 'motorPower',
              dataIndex: 'motorPower',
            },
            {
              title: "力矩（伺服） [Nm]",
              key: 'motorTorque',
              dataIndex: 'motorTorque',
            },
            {
              title: "电流 [A]",
              key: 'motorCurrent',
              dataIndex: 'motorCurrent',
            },
            {
              title: "速度 [rpm]",
              key: 'motorSpeed',
              dataIndex: 'motorSpeed',
            },
            {
              title: "功率因数",
              key: 'motorPowerFactor',
              dataIndex: 'motorPowerFactor',
            },
            {
              title: "频率 [Hz]",
              key: 'motorFrequency',
              dataIndex: 'motorFrequency',
            },
            {
              title: "抱闸",
              key: 'motorBrake',
              dataIndex: 'motorBrake',
            },

          ]}
        ></ProDescriptions>
        <ProDescriptions
          // title={<div style={{ fontSize: '14px' }}>电机铭牌信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={4}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                workMotorWiring: stackerMotorWiringMap.get(props.row.workMotorWiring),
              },
            });
          }}
          columns={[
            {
              title: "工作时电机接线方式",
              key: 'workMotorWiring',
              dataIndex: 'workMotorWiring',
            },
          ]}
        ></ProDescriptions>
        <ProDescriptions
          title={<div style={{ fontSize: '14px' }}>电机编码器信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={3}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                motorEncoderInterface: stackerEncoderInterfaceMap.get(props.row.motorEncoderInterface),
                motorEncoderType: props.row.motorEncoderType,
                motorEncoderSigPolarity: stackerSigPolarityMap.get(props.row.motorEncoderSigPolarity),
              },
            });
          }}
          columns={[
            {
              title: "编码器接口",
              key: 'motorEncoderInterface',
              dataIndex: 'motorEncoderInterface',
            },
            {
              title: "编码器类型",
              key: 'motorEncoderType',
              dataIndex: 'motorEncoderType',
            },
            {
              title: "信号极性",
              key: 'motorEncoderSigPolarity',
              dataIndex: 'motorEncoderSigPolarity',
            },
          ]}
        ></ProDescriptions>
        <ProDescriptions
          title={<div style={{ fontSize: '14px' }}>位置编码器信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={3}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                posEncoderManufacturer: props.row.posEncoderManufacturer,
                posEncoderType: props.row.posEncoderType,
                posEncoderInterface: stackerEncoderInterfaceMap.get(props.row.posEncoderInterface),
              },
            });
          }}
          columns={[
            {
              title: "编码器厂家",
              key: 'posEncoderManufacturer',
              dataIndex: 'posEncoderManufacturer',
            },
            {
              title: "型号",
              key: 'posEncoderType',
              dataIndex: 'posEncoderType',
            },
            {
              title: "编码器接口",
              key: 'posEncoderInterface',
              dataIndex: 'posEncoderInterface',
            },
          ]}
        ></ProDescriptions>
      </div>
    )
  } else {
    if (props.row.controlMode === 2) {
      return (
        <div>
          <ProDescriptions
            title={<div style={{ fontSize: '14px' }}>基本信息</div>}
            style={{ marginTop: '20px' }}
            contentStyle={{ lineHeight: 0.4 }}
            labelStyle={{ lineHeight: 0.4, color: 'grey' }}
            column={4}
            actionRef={props.actionRef}
            request={async() => {
              return Promise.resolve({
                success: true,
                data: {
                  hardwareIdentifier: props.row.hardwareIdentifier,
                  driveType: driveTypeMap.get(props.row.driveType),
                  motorOrderNum: props.row.motorOrderNum,

                  loadType: loadTypeMap.get(props.row.loadType),
                  mechanicalStructure: mechanicalStructureMap.get(props.row.mechanicalStructure),
                  controlMode: controlModeMap.get(props.row.controlMode),
                  commTelegram: commTelegramMap.get(props.row.commTelegram),
                  additionalTelegram: additionalTelegramMap.get(props.row.additionalTelegram),
                },
              });
            }}
            columns={[
              {
                title: "硬件标识符",
                key: 'hardwareIdentifier',
                dataIndex: 'hardwareIdentifier',
              },
              {
                title: "驱动类型",
                key: 'driveType',
                dataIndex: 'driveType',
              },
              {
                title: "电机订货号",
                key: 'motorOrderNum',
                dataIndex: 'motorOrderNum',
              },
              {
                title: "负载类型",
                key: 'loadType',
                dataIndex: 'loadType',
              },
              {
                title: "机械结构",
                key: 'mechanicalStructure',
                dataIndex: 'mechanicalStructure',
              },
              {
                title: "控制模式",
                key: 'controlMode',
                dataIndex: 'controlMode',
              },
              {
                title: "通讯报文",
                key: 'commTelegram',
                dataIndex: 'commTelegram',
              },
              {
                title: "附加报文",
                key: 'additionalTelegram',
                dataIndex: 'additionalTelegram',
              },
            ]}
          ></ProDescriptions>
          <ProDescriptions
            title={<div style={{ fontSize: '14px' }}>V90 Epos模式</div>}
            style={{ marginTop: '20px' }}
            contentStyle={{ lineHeight: 0.4 }}
            labelStyle={{ lineHeight: 0.4, color: 'grey' }}
            column={4}
            actionRef={props.actionRef}
            request={async() => {
              return Promise.resolve({
                success: true,
                data: {
                  gearRationMotor: props.row.gearRationMotor,
                  gearRationLoad: props.row.gearRationLoad,
                  loadOneTurnDistance: props.row.loadOneTurnDistance,
                  velocityMax: props.row.velocityMax,
                  
                  increaseTimeEpos: timeMap.get(props.row.increaseTimeEpos),
                  decreaseTimeEpos: timeMap.get(props.row.decreaseTimeEpos),
                },
              });
            }}
            columns={[
              {
                title: "齿轮比电机转数",
                key: 'gearRationMotor',
                dataIndex: 'gearRationMotor',
              },
              {
                title: "齿轮比负载转数",
                key: 'gearRationLoad',
                dataIndex: 'gearRationLoad',
              },
              {
                title: "负载一圈的距离 [mm或°]",
                key: 'loadOneTurnDistance',
                dataIndex: 'loadOneTurnDistance',
              },
              {
                title: "设备最大速度Vmax [m/s]",
                key: 'velocityMax',
                dataIndex: 'velocityMax',
              },
              {
                title: "0-Vmax时间 [s]",
                key: 'increaseTimeEpos',
                dataIndex: 'increaseTimeEpos',
              },
              {
                title: "Vmax-0时间 [s]",
                key: 'decreaseTimeEpos',
                dataIndex: 'decreaseTimeEpos',
              },
            ]}
          ></ProDescriptions>
        </div>
      )
    } else {
      return (
        <ProDescriptions
          title={<div style={{ fontSize: '14px' }}>基本信息</div>}
          style={{ marginTop: '20px' }}
          contentStyle={{ lineHeight: 0.4 }}
          labelStyle={{ lineHeight: 0.4, color: 'grey' }}
          column={4}
          actionRef={props.actionRef}
          request={async() => {
            return Promise.resolve({
              success: true,
              data: {
                hardwareIdentifier: props.row.hardwareIdentifier,
                driveType: driveTypeMap.get(props.row.driveType),
                motorOrderNum: props.row.motorOrderNum,

                loadType: loadTypeMap.get(props.row.loadType),
                mechanicalStructure: mechanicalStructureMap.get(props.row.mechanicalStructure),
                controlMode: controlModeMap.get(props.row.controlMode),
                commTelegram: commTelegramMap.get(props.row.commTelegram),
                additionalTelegram: additionalTelegramMap.get(props.row.additionalTelegram),
              },
            });
          }}
          columns={[
            {
              title: "硬件标识符",
              key: 'hardwareIdentifier',
              dataIndex: 'hardwareIdentifier',
            },
            {
              title: "驱动类型",
              key: 'driveType',
              dataIndex: 'driveType',
            },
            {
              title: "电机订货号",
              key: 'motorOrderNum',
              dataIndex: 'motorOrderNum',
            },
            {
              title: "负载类型",
              key: 'loadType',
              dataIndex: 'loadType',
            },
            {
              title: "机械结构",
              key: 'mechanicalStructure',
              dataIndex: 'mechanicalStructure',
            },
            {
              title: "控制模式",
              key: 'controlMode',
              dataIndex: 'controlMode',
            },
            {
              title: "通讯报文",
              key: 'commTelegram',
              dataIndex: 'commTelegram',
            },
            {
              title: "附加报文",
              key: 'additionalTelegram',
              dataIndex: 'additionalTelegram',
            },
          ]}
        ></ProDescriptions>
      )
    }
  }

};

const SalesNeedInfoDescription = forwardRef<unknown, SalesNeedInfoProps>(Content);

export default SalesNeedInfoDescription;